package com.socodethis.spaceex;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;

public class DebugHUD {
	
	final int DEFAULT_WIDTH  = 64;
	final int DEFAULT_HEIGHT = 32;
	final String DEFAULT_TEXT = "Hello World!";
	
	int width;
	int height;
	String text;
	Color hudColor;
	Sprite sprite;
	Texture texture;
	Pixmap pixmap;
	String string;
	
	public DebugHUD() {
		width = DEFAULT_WIDTH;
		height = DEFAULT_HEIGHT;
		text = DEFAULT_TEXT;
		hudColor = Color.GRAY;
		sprite = null;
		texture = null;
		pixmap = null;
		string = "";
	}
	
	public void generatePixmap() {
		if ( pixmap == null ) {
			pixmap = new Pixmap( width, height, Format.RGBA8888 );
			pixmap.setColor( Color.WHITE );
			pixmap.fill();
		}
		//clear the panel
		pixmap.setColor( Color.WHITE );
		pixmap.fill();
		
		//drawing operations to display info on panel go here
		pixmap.setColor(Color.BLACK);
		
		//D
		pixmap.drawPixel(0, 0);
		pixmap.drawPixel(1, 0);
		pixmap.drawPixel(2, 1);
		pixmap.drawPixel(2, 2);
		pixmap.drawPixel(1, 3);
		pixmap.drawPixel(0, 1);
		pixmap.drawPixel(0, 2);
		pixmap.drawPixel(0, 3);
		
		//E
		pixmap.drawPixel(4, 0);
		pixmap.drawPixel(5, 0);
		pixmap.drawPixel(6, 0);
		pixmap.drawPixel(4, 1);
		pixmap.drawPixel(5, 1);
		pixmap.drawPixel(4, 2);
		pixmap.drawPixel(4, 3);
		pixmap.drawPixel(5, 3);
		pixmap.drawPixel(6, 3);
		
		//B
		pixmap.drawPixel(8, 0);
		pixmap.drawPixel(8, 1);
		pixmap.drawPixel(8, 2);
		pixmap.drawPixel(8, 3);
		pixmap.drawPixel(9, 3);
		pixmap.drawPixel(10, 3);
		pixmap.drawPixel(10, 2);
		pixmap.drawPixel(10, 1);
		pixmap.drawPixel(9, 1);
		
		//U
		pixmap.drawPixel(12, 0);
		pixmap.drawPixel(12, 1);
		pixmap.drawPixel(12, 2);
		pixmap.drawPixel(12, 3);
		pixmap.drawPixel(13, 3);
		pixmap.drawPixel(14, 0);
		pixmap.drawPixel(14, 1);
		pixmap.drawPixel(14, 2);
		pixmap.drawPixel(14, 3);
		
		//G
		pixmap.drawPixel(16, 0);
		pixmap.drawPixel(16, 1);
		pixmap.drawPixel(16, 2);
		pixmap.drawPixel(16, 3);
		pixmap.drawPixel(17, 0);
		pixmap.drawPixel(18, 0);
		pixmap.drawPixel(17, 3);
		pixmap.drawPixel(18, 3);
		pixmap.drawPixel(18, 2);
		pixmap.drawPixel(17, 2);
		
	}
	
	public void generateTexture() {
		this.generatePixmap();
		if ( texture == null ) {
			texture = new Texture( pixmap );
		}
		texture.draw( pixmap, 0, 0 );
	}
	
	public Sprite getHUDSprite() {
		this.generateTexture();
		if ( sprite == null ) {
			sprite = new Sprite( texture );
			sprite.setSize( DEFAULT_WIDTH * 1.0f, DEFAULT_HEIGHT * 1.0f );
			sprite.setPosition( 0.0f, 0.0f );
		}
		sprite.setSize( DEFAULT_WIDTH * 0.075f, DEFAULT_HEIGHT * 0.045f );
		sprite.setPosition( 0.1f, 1.45f );
		return sprite;
	}
	
	public void addHUDString(String string){
		this.string = "\n" + string;
		 //font.setColor(1.0f, 1.0f, 1.0f, 1.0f);
		 //font.draw(spriteBatch, str, 25, 160);
	}
	
	public String returnHUDString(){
		return string;
	}
	
	
}
